import http from "../service/http.js"
export const orderModule = {
	// 订单模块
	state: {

		// actOrder:"", //当期选中订单
		// OrderList: [
		// 	// 订单列表
		// ],
		
		orderStatus: [
			// 订单状态分类
			{
				label: '全部',
				val:-1
			},
			{
				label: '待付款',
				val:0
			},
			{
				label: '待发货',
				val:1
			},
			{
				label: '待收货',
				val:2
			},
			{
				label: '已完成',
				val:3
			},
			{
				label: '退款／售后',
				val:4
			},
			{
				label: '已关闭',
				val:5
			}
		],
		orderCounts:[
			// 订单新增数量
			// {
			// 	count: 17
			// 	orderState: 0
			// }
		],
		takeAddress: 
		{
			// 收货地址对象
			// addresAlias: null
			// addresType: 0
			// address: "榄树排东街12巷3号"
			// city: "广州市"
			// county: "黄埔区"
			// createBy: ""
			// createTime: "2021-01-11 03:40:27"
			// fixIphone: null
			// id: 20
			// iphone: "18202074132"
			// isDefault: 1
			// params: Object
			// province: "广东省"
			// remark: null
			// searchValue: null
			// takeName: "饶东俊"
			// updateBy: ""
			// updateTime: "2021-01-11 03:40:59"
			// userId: 3
		},

		focusTakeAddress: {
			// 集中收货地址
			// addresAlias: null
			// addresType: 0
			// address: "榄树排东街12巷3号"
			// city: "广州市"
			// county: "黄埔区"
			// createBy: ""
			// createTime: "2021-01-11 03:40:27"
			// fixIphone: null
			// id: 20
			// iphone: "18202074132"
			// isDefault: 1
			// params: Object
			// province: "广东省"
			// remark: null
			// searchValue: null
			// takeName: "饶东俊"
			// updateBy: ""
			// updateTime: "2021-01-11 03:40:59"
			// userId: 3
		},
		editOrderFrom: {
			goodsList: [
				// 买的商品列表
			]
		},
		invoiceData: {
			// 发票数据
			// orderNo:"", //订单号
			invoiceType: null, //发票类型 0：个人 1:单位
			invoiceTitle: "", //发票抬头
			invoiceTaxNo: "", //发票税号
			invoiceEmail: "", //开票邮箱
			// invoiceTax:"", //开票税金
			vatCompanyAddress: "", //公司地址
			vatTelphone: "", //联系电话
			vatBankName: "", //开户银行
			vatBankAccount: "", //银行账号
		}
	},
	mutations: {

		// setOrderList(state, OrderList) {

		// 	state.OrderList = OrderList;
		// },
		setOrderFrom(state, editOrderFrom) {

			state.editOrderFrom = editOrderFrom;
		},
		setOrderCount(state, orderCounts){
			state.orderCounts=orderCounts
		},
		clearOrderCount(state, orderCounts){
			state.orderCounts=[]
		},
		setBuyGoods(state, goodsList) {
			// 设置购买的商品列表
			state.editOrderFrom.goodsList = goodsList
		},
		setActOrder(state, actOrder) {

			state.actOrder = actOrder;
		},
		setTakeAddress(state, selectAddress) {
			// 设置收货地址
			state.takeAddress = selectAddress
		},
		setFocusTakeAddress(state, selectAddress) {
			// 设置集中收货地址
			state.focusTakeAddress = selectAddress
		},
		setInvoiceData(state, invoiceData) {
			// 设置发票数据
			state.invoiceData = invoiceData
		}

	},
	getters: {

	},
	actions: {

		getOrderList: async function({
				commit,
				state
			}, params
			// {
			// status
			// 订单状态：-1->全部；0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭		
			// Available values : -1, 0, 1, 2, 3, 4 ,5
			// Default value : -1
			// }
		) {
			// 按状态分页获取用户订单列表
			return await new Promise((resolve, reject) => {

				http.get('/orders/list',params).then(res => {

					console.log("按状态分页获取用户订单列表成功", res)
					// let data = res.data.data


					resolve(res)

				}).catch(err => {
					console.log("按状态分页获取用户订单列表失败", err)
					reject(err)
				})
			})
		},
		getOrderInfo: async function({
				commit,
				state
			}, params
			// {
			// orderNo 订单号
			//获取订单详细信息
			// }
		) {
			// 按状态分页获取用户订单列表
			return await new Promise((resolve, reject) => {

				http.get(`/orders/getInfo/${params.orderNo}`).then(res => {

					console.log("获取订单详细信息成功", res)
					// let data = res.data.data


					resolve(res)

				}).catch(err => {
					console.log("获取订单详细信息失败", err)
					reject(err)
				})
			})
		},
		getPostageTemplate: async function({
				commit,
				state
			},
			 // {
			 //    "searchValue": null,
			 //    "createBy": "",
			 //    "createTime": "2021-02-02 16:40:33",
			 //    "updateBy": "",
			 //    "updateTime": "2021-02-02 17:03:03",
			 //    "remark": null,
			 //    "params": {},
			 //    "id": 1,
			 //    "modelName": null,
			 //    "pricingMode": 0,
			 //    "meetAmount": 30,
			 //    "restrictAddress": "天津,北京"
			 //  }
		) {
			// 查询运费模板
			return await new Promise((resolve, reject) => {
		
				http.get(`/orders/template`).then(res => {
		
					console.log("查询运费模板成功", res)
					// let data = res.data.data
		
		
					resolve(res)
		
				}).catch(err => {
					console.log("查询运费模板失败", err)
					reject(err)
				})
			})
		},
		getOrderCount: async function({
				commit,
				state
			}
			// 
			//查询订单状态数量
			// }
		) {
			// 按状态分页获取用户订单列表
			return await new Promise((resolve, reject) => {

				http.get(`/orders/orderCount`).then(res => {

					console.log("查询订单状态数量成功", res)
					let data = res.data.data
					commit("setOrderCount",data)
					resolve(res)

				}).catch(err => {
					console.log("查询订单状态数量失败", err)
					reject(err)
				})
			})
		},
		addOrder: async function({ //添加订单
				commit,
				state
			}, params
			// {
			// "Order": "string",
			//   "billType": 0,
			//   "buyOrderId": "string",
			//   "buyId": 0,
			//   "buyNickname": "string",
			//   "city": "string",
			//   "county": "string",
			//   "buyCount": 0,
			//   "goodsList": [
			//     {
			//       "buyCount": 0,
			//       "createBy": "string",
			//       "createTime": "2021-01-10T13:47:43.438Z",
			//       "goodsId": 0,
			//       "goodsName": "string",
			//       "goodsPrise": 0,
			//       "id": 0,
			//       "orderId": 0,
			//       "orderNo": "string",
			//       "params": {},
			//       "remark": "string",
			//       "searchValue": "string",
			//       "totalMoney": 0,
			//       "updateBy": "string",
			//       "updateTime": "2021-01-10T13:47:43.438Z"
			//     }
			//   ],
			//   "goodsPrice": 0,
			//   "iphone": "string",
			//   "jpOrdersInvoice": {
			//     "createBy": "string",
			//     "createTime": "2021-01-10T13:47:43.438Z",
			//     "id": 0,
			//     "invoicEmail": "string",
			//     "invoiceTax": 0,
			//     "invoiceTaxNo": 0,
			//     "invoiceTitle": "string",
			//     "invoiceType": "string",
			//     "orderNo": "string",
			//     "params": {},
			//     "remark": "string",
			//     "searchValue": "string",
			//     "updateBy": "string",
			//     "updateTime": "2021-01-10T13:47:43.438Z",
			//     "vatBankAccount": "string",
			//     "vatBankName": "string",
			//     "vatCompanyOrder": "string",
			//     "vatTelphone": "string"
			//   },
			//   "messageInfo": "string",
			//   "orderFreight": 0,
			//   "orderPrice": 0,
			//   "payDate": "2021-01-10T13:47:43.438Z",
			//   "payType": 0,
			//   "pickType": 0,
			//   "province": "string",
			//   "returnType": 0,
			//   "stockType": 0,
			//   "takeName": "string"
			// }
		) {
			// console.log("params", params)
			commit("setOrderFrom", params)
			return await new Promise((resolve, reject) => {

				http.post('/orders/add', state.editOrderFrom).then(res => {

					console.log("添加订单信息成功", res)
					// let data = res.data.data
					// dispatch("getOrderList")
					resolve(res)

				}).catch(err => {
					console.log("添加订单信息失败", err)
					reject(err)
				})
			})
		},
		payAgain:async function({ //再次支付
				commit,
				state
			}, params
			// {
			// orderNo
			// }
		) {
			// console.log("params", params)
			return await new Promise((resolve, reject) => {

				http.get(`/orders/pay/${params.orderNo}`).then(res => {

					console.log("再次支付成功", res)
					// let data = res.data.data
					// dispatch("getOrderList")
					resolve(res)

				}).catch(err => {
					console.log("再次支付失败", err)
					reject(err)
				})
			})
		},
		cancelOrder: async function({ //取消订单
				commit,
				state

			}, params
			// {
			// orderNo //订单号
			// }
		) {
			// console.log("params", params)
			return await new Promise((resolve, reject) => {

				http.post(`/orders/cancelUserOrder/${params.orderNo}`).then(res => {

					console.log("取消订单成功", res)
					// let data = res.data.data
					// dispatch("getOrderList")
					resolve(res)

				}).catch(err => {
					console.log("取消订单失败", err)
					reject(err)
				})
			})
		},
		removeOrder: async function({ //关闭订单
				commit,
				state
		
			}, params
			// {
			// orderNo //订单号
			// }
		) {
			// console.log("params", params)
			return await new Promise((resolve, reject) => {
		
				http.post(`/orders/remove/${params.orderNo}`).then(res => {
		
					console.log("删除订单成功", res)
					// let data = res.data.data
					// dispatch("getOrderList")
					resolve(res)
		
				}).catch(err => {
					console.log("删除订单失败", err)
					reject(err)
				})
			})
		},
		confirmOrder: async function({ //确认收货
				commit,
				state

			}, params
			// {
			// orderNo //订单号
			// }
		) {
			// console.log("params", params)
			return await new Promise((resolve, reject) => {

				http.post('/orders/updateOrdersConfirm', params).then(res => {

					console.log("确认收货成功", res)
					let data = res.data.data
					// dispatch("getOrderList")
					resolve(data)

				}).catch(err => {
					console.log("确认收货失败", err)
					reject(err)
				})
			})
		},
		
		// payFinish: async function({ //支付完成
		// 		commit,
		// 		state

		// 	}, params
		// 	// {
		// 	// orderNo //订单号
		// 	// }
		// ) {
		// 	// console.log("params", params)
		// 	return await new Promise((resolve, reject) => {

		// 		http.post('/orders/updateOrdersPayInfo', params).then(res => {

		// 			console.log("确认支付成功", res)
		// 			let data = res.data.data
		// 			// dispatch("getOrderList")
		// 			resolve(data)

		// 		}).catch(err => {
		// 			console.log("确认支付失败", err)
		// 			reject(err)
		// 		})
		// 	})
		// },
	}
}
